import java.sql.*;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;

public class LoginForm extends javax.swing.JFrame {   
    
    public LoginForm() {
        initComponents();  
    }
     
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jOptionPane = new javax.swing.JOptionPane();
        StudentForm = new javax.swing.JFrame();
        lblDilwsi = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        AdminForm = new javax.swing.JFrame();
        lblNewStudent = new javax.swing.JLabel();
        txtNewFirstNameStudent = new javax.swing.JTextField();
        lblNewLastNameStudent = new javax.swing.JLabel();
        txtNewLastNameStudent = new javax.swing.JTextField();
        lblNewUsernameStudent = new javax.swing.JLabel();
        txtNewUserNameStudent = new javax.swing.JTextField();
        lblNewPasswordStudent = new javax.swing.JLabel();
        txtNewPasswordStudent = new javax.swing.JTextField();
        lblNewAMStudent = new javax.swing.JLabel();
        txtNewAMStudent = new javax.swing.JTextField();
        lblNewExaminoStudent = new javax.swing.JLabel();
        txtNewExaminoStudent = new javax.swing.JTextField();
        lblNewDMStudent = new javax.swing.JLabel();
        txtNewDMStudent = new javax.swing.JTextField();
        btnNewStudent = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        lblAddNewStudent = new javax.swing.JLabel();
        lblAddNewCourse = new javax.swing.JLabel();
        lblKwdikosNewMathima = new javax.swing.JLabel();
        txtKwdikosNewMathima = new javax.swing.JTextField();
        lblTitlosNewMathima = new javax.swing.JLabel();
        txtTitlosNewMathima = new javax.swing.JTextField();
        lblDMNewMathima = new javax.swing.JLabel();
        txtDMNewMathima = new javax.swing.JTextField();
        lblExaminoNewMathima = new javax.swing.JLabel();
        spnrExamino = new javax.swing.JSpinner();
        lblTyposNewMathima = new javax.swing.JLabel();
        cboTyposNewMathima = new javax.swing.JComboBox();
        btnNewMathima = new javax.swing.JButton();
        jFrame1 = new javax.swing.JFrame();
        txtUsername = new javax.swing.JTextField();
        txtPassword = new javax.swing.JPasswordField();
        btnLogin = new javax.swing.JButton();
        lblTitle = new javax.swing.JLabel();
        lblUsername = new javax.swing.JLabel();
        lblPassword = new javax.swing.JLabel();

        StudentForm.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblDilwsi.setText("ΔΗΛΩΣΗ ΜΑΘΗΜΑΤΩΝ");

        jScrollPane1.setViewportView(jList1);

        jButton1.setText("Ανανέωση Λίστας");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout StudentFormLayout = new javax.swing.GroupLayout(StudentForm.getContentPane());
        StudentForm.getContentPane().setLayout(StudentFormLayout);
        StudentFormLayout.setHorizontalGroup(
            StudentFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(StudentFormLayout.createSequentialGroup()
                .addGroup(StudentFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(StudentFormLayout.createSequentialGroup()
                        .addGap(193, 193, 193)
                        .addComponent(lblDilwsi))
                    .addGroup(StudentFormLayout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(StudentFormLayout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addComponent(jButton1)))
                .addContainerGap(235, Short.MAX_VALUE))
        );
        StudentFormLayout.setVerticalGroup(
            StudentFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(StudentFormLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(lblDilwsi)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jButton1)
                .addContainerGap(114, Short.MAX_VALUE))
        );

        AdminForm.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblNewStudent.setText("Όνομα Φοιτητή:");

        lblNewLastNameStudent.setText("Επώνυμο Φοιτητή:");

        lblNewUsernameStudent.setText("Usename:");

        lblNewPasswordStudent.setText("Password:");

        lblNewAMStudent.setText("ΑΜ:");

        lblNewExaminoStudent.setText("Εξάμηνο:");

        lblNewDMStudent.setText("ΔΜ:");

        btnNewStudent.setText("Καταχώρηση");
        btnNewStudent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewStudentActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        lblAddNewStudent.setText("ΚΑΤΑΧΩΡΗΣΗ ΝΕΟΥ ΦΟΙΤΗΤΗ");

        lblAddNewCourse.setText("ΚΑΤΑΧΩΡΗΣΗ ΝΕΟΥ ΜΑΘΗΜΑΤΟΣ");

        lblKwdikosNewMathima.setText("Κωδικός Μαθήματος:");

        lblTitlosNewMathima.setText("Τίτλος Μαθήματος:");

        lblDMNewMathima.setText("ΔΜ:");

        lblExaminoNewMathima.setText("Εξάμηνο:");

        //spnrExamino.setModel(new javax.swing.SpinnerNumberModel());
        SpinnerModel model = new SpinnerNumberModel(1, 1, 8, 1);
        JSpinner spnrExamino = new JSpinner(model);
        Integer currentValue = (Integer)spnrExamino.getValue();

        lblTyposNewMathima.setText("Τύπος:");

        cboTyposNewMathima.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "upoxrewtiko", "epilogis" }));
        cboTyposNewMathima.setEditor(null);

        btnNewMathima.setText("Καταχώρηση");
        btnNewMathima.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewMathimaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout AdminFormLayout = new javax.swing.GroupLayout(AdminForm.getContentPane());
        AdminForm.getContentPane().setLayout(AdminFormLayout);
        AdminFormLayout.setHorizontalGroup(
            AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AdminFormLayout.createSequentialGroup()
                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AdminFormLayout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(AdminFormLayout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(lblAddNewStudent)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(AdminFormLayout.createSequentialGroup()
                                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(AdminFormLayout.createSequentialGroup()
                                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lblNewDMStudent)
                                            .addComponent(lblNewExaminoStudent)
                                            .addComponent(lblNewAMStudent)
                                            .addComponent(lblNewPasswordStudent)
                                            .addComponent(lblNewUsernameStudent))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtNewUserNameStudent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtNewPasswordStudent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtNewAMStudent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtNewExaminoStudent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtNewDMStudent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(AdminFormLayout.createSequentialGroup()
                                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(AdminFormLayout.createSequentialGroup()
                                                .addComponent(lblNewLastNameStudent)
                                                .addGap(30, 30, 30))
                                            .addGroup(AdminFormLayout.createSequentialGroup()
                                                .addComponent(lblNewStudent)
                                                .addGap(41, 41, 41)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtNewFirstNameStudent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtNewLastNameStudent, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, AdminFormLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnNewStudent)
                        .addGap(99, 99, 99)))
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AdminFormLayout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(lblAddNewCourse))
                    .addGroup(AdminFormLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblKwdikosNewMathima)
                            .addComponent(lblTitlosNewMathima)
                            .addComponent(lblDMNewMathima)
                            .addComponent(lblExaminoNewMathima)
                            .addComponent(lblTyposNewMathima))
                        .addGap(59, 59, 59)
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtTitlosNewMathima)
                            .addComponent(txtKwdikosNewMathima)
                            .addComponent(txtDMNewMathima)
                            .addComponent(spnrExamino)
                            .addComponent(cboTyposNewMathima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(AdminFormLayout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addComponent(btnNewMathima)))
                .addContainerGap(65, Short.MAX_VALUE))
        );
        AdminFormLayout.setVerticalGroup(
            AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, AdminFormLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(AdminFormLayout.createSequentialGroup()
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(AdminFormLayout.createSequentialGroup()
                                .addComponent(lblAddNewStudent)
                                .addGap(42, 42, 42)
                                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblNewStudent)
                                    .addComponent(txtNewFirstNameStudent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblNewLastNameStudent)
                                    .addComponent(txtNewLastNameStudent))
                                .addGap(18, 18, 18)
                                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblNewUsernameStudent)
                                    .addComponent(txtNewUserNameStudent))
                                .addGap(18, 18, 18)
                                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblNewPasswordStudent)
                                    .addComponent(txtNewPasswordStudent))
                                .addGap(18, 18, 18)
                                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblNewAMStudent)
                                    .addComponent(txtNewAMStudent))
                                .addGap(18, 18, 18)
                                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblNewExaminoStudent)
                                    .addComponent(txtNewExaminoStudent))
                                .addGap(18, 18, 18)
                                .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(lblNewDMStudent)
                                    .addComponent(txtNewDMStudent))
                                .addGap(50, 50, 50)
                                .addComponent(btnNewStudent))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(AdminFormLayout.createSequentialGroup()
                        .addComponent(lblAddNewCourse)
                        .addGap(42, 42, 42)
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblKwdikosNewMathima)
                            .addComponent(txtKwdikosNewMathima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblTitlosNewMathima)
                            .addComponent(txtTitlosNewMathima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblDMNewMathima)
                            .addComponent(txtDMNewMathima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblExaminoNewMathima)
                            .addComponent(spnrExamino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(AdminFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblTyposNewMathima)
                            .addComponent(cboTyposNewMathima, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnNewMathima)
                        .addGap(93, 93, 93))))
        );

        jFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("LogIn");

        btnLogin.setText("Login");
        btnLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoginActionPerformed(evt);
            }
        });

        lblTitle.setText("Εισαγωγή στο Σύστημα");

        lblUsername.setText("Username:");

        lblPassword.setText("Password:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblPassword)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblUsername)
                        .addGap(46, 46, 46)
                        .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
                .addComponent(btnLogin)
                .addGap(73, 73, 73))
            .addGroup(layout.createSequentialGroup()
                .addGap(113, 113, 113)
                .addComponent(lblTitle)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(lblTitle)
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUsername))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLogin)
                    .addComponent(lblPassword))
                .addContainerGap(139, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

//    private void FillListBox(){
//        
//    DefaultListModel m = new DefaultListModel();
//    try{
//        String sql="select * from mathima";
//        pst.conn.prepareStatement(sql);
//        rs=pst.executeQuery();
//        
//        while(rs.next()){
//        String titlos=rs.getString("titlos");
//        m.addElement(titlos);
//                }
//        jList1.setModel(m);
//    }catch(Exception e){
//        JOptionPane.showMessageDialog(null, e);
//    }
//    }
    
    private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoginActionPerformed
        
        String user; //Apothikevetai to username pou eisagei o xristis
        String user1=""; //To username pou erxetai apo tin vasi gia tin taftopoihsh
        String pass1=""; //To password pou erxetai apo tn vasia apo to query gia tn taftopoihsh
        String typos=""; //O typos tou xristi: foititis, kathigitis, administrator
        user = txtUsername.getText();
        char[] strpass = txtPassword.getPassword();
   
             String driverClassName = "org.postgresql.Driver";
             String url = "jdbc:postgresql://aetos.it.teithe.gr:5432/db2lab4";
             Connection dbConnection = null;
             Statement statement = null;

             ResultSet rs;
             ResultSet rs2;
                
        
        try {
             
            Class.forName(driverClassName);
            dbConnection = DriverManager.getConnection (url, "db160", "63L70");
            statement = dbConnection.createStatement();

            String selectString = "SELECT * FROM Users where Username='"+user+"'";
            

            rs = statement.executeQuery(selectString);
            

         
            while (rs.next()) {
                    user1 = rs.getString("Username");
                    pass1 = rs.getString("Pasword");
                    typos = rs.getString("Typos");
            }

            statement.close();
            dbConnection.close();

                if (user.equals(user1) && pass1.equals(new String (strpass)) && typos.equals("foititis")) {
                    //nea connection

                    String selectString2 = "SELECT * FROM foititis where Username='"+user+"'";

                    rs2 = statement.executeQuery(selectString2);

                    String onoma = rs2.getString("Onoma");
                    int dm=rs2.getInt("dm");

                    Student foititis = new Student(user1);
                    foititis.setDM(dm);
                    this.dispose();
                    StudentForm.pack();
                    StudentForm.show();
                    }
                
                else if (user.equals(user1) && pass1.equals(new String (strpass)) && typos.equals("kathigitis")){

                    }

                else if (user.equals(user1) && pass1.equals(new String (strpass)) && typos.equals("administrator")){
                    this.dispose();
                    AdminForm.pack();
                    AdminForm.show();
                    }
                
                else {
                JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
                }

            } 
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());

        }
        
    }//GEN-LAST:event_btnLoginActionPerformed

    private void btnNewStudentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewStudentActionPerformed
    String driverClassName = "org.postgresql.Driver";
             String url = "jdbc:postgresql://aetos.it.teithe.gr:5432/db2lab4";
             Connection dbConnection = null;
             PreparedStatement pst = null;
             PreparedStatement pst2 = null;
                
        try {
            Class.forName(driverClassName);
            dbConnection = DriverManager.getConnection (url, "db160", "63L70");
            
            String insertString = "INSERT INTO users(userfirstname, userlastname, username, pasword, typos) VALUES (?,?,?,?,?) ";
            
            pst = dbConnection.prepareStatement(insertString);
            
            pst.setString(1, txtNewFirstNameStudent.getText());
            pst.setString(2, txtNewLastNameStudent.getText());
            pst.setString(3, txtNewUserNameStudent.getText());
            pst.setString(4, txtNewPasswordStudent.getText());
            pst.setString(5, "foititis");
            pst.executeUpdate();
            pst.close();
            
            String insertString2 = "INSERT INTO foititis(userusername, am, examino, dm) VALUES (?,?,?,?) ";
            
            pst2 = dbConnection.prepareStatement(insertString2);
            
            pst2.setString(1, txtNewUserNameStudent.getText());
            pst2.setInt(2, new Integer(txtNewAMStudent.getText()));
            pst2.setInt(3, new Integer(txtNewExaminoStudent.getText()));
            pst2.setInt(4, new Integer(txtNewDMStudent.getText()));
            pst2.executeUpdate();
            pst2.close();
            
            dbConnection.close();

            JOptionPane.showMessageDialog(null,"Η καταχώρηση έγινε με επιτυχία","Success",JOptionPane.PLAIN_MESSAGE);
            
            txtNewFirstNameStudent.setText("");
            txtNewLastNameStudent.setText("");
            txtNewUserNameStudent.setText("");
            txtNewPasswordStudent.setText("");
            txtNewAMStudent.setText("");
            txtNewExaminoStudent.setText("");
            txtNewDMStudent.setText("");
            } 
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());

        }
    }//GEN-LAST:event_btnNewStudentActionPerformed

    private void btnNewMathimaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewMathimaActionPerformed
        String driverClassName = "org.postgresql.Driver";
             String url = "jdbc:postgresql://aetos.it.teithe.gr:5432/db2lab4";
             Connection dbConnection = null;
             PreparedStatement pst = null;
                
        try {
            Class.forName(driverClassName);
            dbConnection = DriverManager.getConnection (url, "db160", "63L70");
            
            String insertString = "INSERT INTO mathima(id, titlos, dm, examino, tupos) VALUES (?,?,?,?,?) ";
            
            pst = dbConnection.prepareStatement(insertString);
            
            pst.setString(1, txtKwdikosNewMathima.getText());
            pst.setString(2, txtTitlosNewMathima.getText());
            pst.setInt(3, new Integer(txtDMNewMathima.getText()));
            pst.setInt(4, (int) spnrExamino.getValue());
            pst.setString(5, (String) cboTyposNewMathima.getSelectedItem());
            pst.executeUpdate();
            pst.close();
                     
            dbConnection.close();

            JOptionPane.showMessageDialog(null,"Η καταχώρηση έγινε με επιτυχία","Success",JOptionPane.PLAIN_MESSAGE);
            
            txtKwdikosNewMathima.setText("");
            txtTitlosNewMathima.setText("");
            txtDMNewMathima.setText("");
            spnrExamino.setValue(1);
            cboTyposNewMathima.setSelectedIndex(0);
            } 
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());

        }
    }//GEN-LAST:event_btnNewMathimaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String driverClassName = "org.postgresql.Driver";
             String url = "jdbc:postgresql://aetos.it.teithe.gr:5432/db2lab4";
             Connection dbConnection = null;
             PreparedStatement pst = null;
             ResultSet rs;
                
        try {
            Class.forName(driverClassName);
            dbConnection = DriverManager.getConnection (url, "db160", "63L70");
            DefaultListModel m = new DefaultListModel();
    
            String sql="select * from mathima";
            pst=dbConnection.prepareStatement(sql);
            rs=pst.executeQuery();

            while(rs.next()){
            String titlos=rs.getString("titlos");
            m.addElement(titlos);
                    }
            jList1.setModel(m);
  
            } 
        catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LoginForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LoginForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame AdminForm;
    private javax.swing.JFrame StudentForm;
    private javax.swing.JButton btnLogin;
    private javax.swing.JButton btnNewMathima;
    private javax.swing.JButton btnNewStudent;
    private javax.swing.JComboBox cboTyposNewMathima;
    private javax.swing.JButton jButton1;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JList jList1;
    private javax.swing.JOptionPane jOptionPane;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblAddNewCourse;
    private javax.swing.JLabel lblAddNewStudent;
    private javax.swing.JLabel lblDMNewMathima;
    private javax.swing.JLabel lblDilwsi;
    private javax.swing.JLabel lblExaminoNewMathima;
    private javax.swing.JLabel lblKwdikosNewMathima;
    private javax.swing.JLabel lblNewAMStudent;
    private javax.swing.JLabel lblNewDMStudent;
    private javax.swing.JLabel lblNewExaminoStudent;
    private javax.swing.JLabel lblNewLastNameStudent;
    private javax.swing.JLabel lblNewPasswordStudent;
    private javax.swing.JLabel lblNewStudent;
    private javax.swing.JLabel lblNewUsernameStudent;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JLabel lblTitlosNewMathima;
    private javax.swing.JLabel lblTyposNewMathima;
    private javax.swing.JLabel lblUsername;
    private javax.swing.JSpinner spnrExamino;
    private javax.swing.JTextField txtDMNewMathima;
    private javax.swing.JTextField txtKwdikosNewMathima;
    private javax.swing.JTextField txtNewAMStudent;
    private javax.swing.JTextField txtNewDMStudent;
    private javax.swing.JTextField txtNewExaminoStudent;
    private javax.swing.JTextField txtNewFirstNameStudent;
    private javax.swing.JTextField txtNewLastNameStudent;
    private javax.swing.JTextField txtNewPasswordStudent;
    private javax.swing.JTextField txtNewUserNameStudent;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JTextField txtTitlosNewMathima;
    private javax.swing.JTextField txtUsername;
    // End of variables declaration//GEN-END:variables
}
